#ifndef QUEUE_H
#define QUEUE_H


typedef struct queue_t
{
	unsigned char *pbuffer;
	unsigned char	size;
	unsigned char head;
	unsigned char tail;
}queue_t;


#define queue_length(q)					(((q)->head >= (q)->tail) ? ((q)->head - (q)->tail) : ((q)->head + (q)->size - (q)->tail))
#define queue_is_empty(q)				((q)->head == (q)->tail)
#define queue_is_full(q)				(((q)->size>0) && (queue_length(q) >= (q)->size - 1))
#define queue_reset(q)					(q)->head = (q)->tail = 0
#define queue_first(q)					(q)->buffer[(q)->tail]
#define queue_last(q)						(q)->buffer[(q)->head > 0 ? (q)->head - 1 : (q)->size - 1]
#define queue_index(q, i)				(q)->buffer[(q)->tail + i < (q)->size ? (q)->tail + i : (q)->tail + i - (q)->size]


void queue_init(queue_t * q, unsigned char *ptr, unsigned char len);
void queue_enque(queue_t * q, unsigned char e);
unsigned char queue_deque(queue_t * q);

	

#endif /* QUEUE_H */